package com.ruoyi.system.util;

import java.util.ArrayList;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
public  class AmountCalculation {

    public static long jiner(Date ruku, Date chuku) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        // 模拟车辆进入和离开停车场的时间
        String rukushijian =sdf.format(ruku);//入库时间
        String chukushijian =sdf.format(chuku);//出库时间
        // 定义一个日期时间格式化器
        // 定义一个日期时间格式化器
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm");
        // 解析字符串为LocalDateTime对象
        LocalDateTime rukuTime = LocalDateTime.parse(rukushijian, formatter);
        LocalDateTime chukuTime = LocalDateTime.parse(chukushijian, formatter);
        //int tianshu = ((chukuTime.getDayOfMonth() - rukuTime.getDayOfMonth() + 1) - 2);
        long jiner = 0;
        List lind = new ArrayList();
        // 计算停车时间
        Duration duration = Duration.between(rukuTime, chukuTime);
        ParkingLot parkingLot = new ParkingLot();
        // 将时间差转换为分钟
        long minutes = duration.toMinutes();
        System.out.println(""+(minutes*60));
        List<Long> list = parkingLot.getParkingtime(minutes);
        System.out.println(list.get(0));
        if (rukuTime.getDayOfMonth() != chukuTime.getDayOfMonth()||rukuTime.getMonth()!=chukuTime.getMonth()||rukuTime.getYear()!=chukuTime.getYear()) {  //判断日期是否，是同一天
            //计算第一天
            List<Long> diyit = parkingLot.getThefirstday(parkingLot.getday(rukuTime.getMinute(), rukuTime.getHour()), chukuTime.getHour());
            //计算最后一天
            List<Long> zuihou = parkingLot.getLastday(parkingLot.getEvening(chukuTime.getMinute(), chukuTime.getHour()));
            //计算中间天数
            long zhonjianshijian = (((list.get(0))-((diyit.get(0)+diyit.get(1))+(zuihou.get(0)+zuihou.get(1))))/24) * 30;
//          List<Long> shijian=parkingLot.getBaitian(diyit,zuihou);


            jiner = parkingLot.getJiSuan(diyit.get(0), diyit.get(1)) + parkingLot.getJiSuan(zuihou.get(0), zuihou.get(1)) + zhonjianshijian;
            System.out.println("总共:" + jiner);

        } else {
//            if ((rukuTime.getHour()-chukuTime.getHour())>1) {
            List<Long> diyit = parkingLot.getThef(parkingLot.getday(rukuTime.getMinute(), rukuTime.getHour()), parkingLot.getZuihou(chukuTime.getMinute(), chukuTime.getHour()));
            if ((diyit.get(0) + diyit.get(1)) > 1) {
                long londe = parkingLot.getJiSuan(diyit.get(0), diyit.get(1));

                jiner = londe > 50 ? 50 : londe;
                System.out.println("总共:" + (jiner == 50 ? "单天已上线固定金额为30" : jiner));
            } else {
//                jiner = londe > 30 ? 30 : londe;
                System.out.println("免费停车时间为一小时");

            }
        }
        if (jiner<=0){
            return 0;
        }
        return jiner;
    }
}
